package com.jsshse.service.sys.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;


import com.jsshse.service.base.impl.BaseServiceImpl;
import com.jsshse.dao.base.BaseDaoI;
import com.jsshse.dao.sys.ParamGroupDaoI;
import com.jsshse.service.sys.ParamGroupServiceI;
import com.jsshse.util.Pages;
import com.jsshse.util.CommUtil;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

@Service("paramGroupService")
public class ParamGroupServiceImpl extends BaseServiceImpl implements ParamGroupServiceI{
	private static Logger log = Logger.getLogger(ParamGroupServiceImpl.class);
	@Resource
	private BaseDaoI baseDao ;
	@Resource
	private ParamGroupDaoI paramGroupDao ;
	
	@Override
	public boolean add(Map map) {
		String id=CommUtil.getId();
		map.put("id", id);
		return paramGroupDao.add(map);
	}

	@Override
	public boolean delete(String id) {
		return paramGroupDao.delete(id);
	}

	@Override
	public boolean update(Map map) {
		return paramGroupDao.update(map);

	}

	@Override
	public Map queryById(String id) {
		return paramGroupDao.queryById(id);
	}
	

	@Override
	public Pages queryForList(Pages pages) {
		
		pages.setTotal(paramGroupDao.queryForListCnt(pages.getQueryCondition()));
		List list=paramGroupDao.queryForListByPage(pages.getAllQueryCond(), pages.getPageStart(), pages.getPageSize());
		pages.setDataList(list);
		return pages;
	}
 
	//@Cacheable(value = "param_group", key ="'queryParamByTag'+(#info.length>1?(#info[0]+#info[1]+#info[2]):#info[0])")
	public List queryParamByTag(String[] info) {
		Map m=paramGroupDao.queryById(info[0]);
		log.debug(m);
		String sqlText=(String)m.get("sql_text");
		for (int i = 1; i < info.length; i++) {
			sqlText=sqlText.replaceAll("\\$\\{"+i+"\\}", info[i]);
		}
		
		return baseDao.queryBySqlText(sqlText);
	}
}
